package com.aplink.generic.xmlparser.ctrlformat;

import org.w3c.dom.Node;

import android.text.TextUtils;

import com.aplink.generic.pojo.controlspec.GallerySpec;
import com.aplink.generic.xmlparser.XMLPaserUtil;

public class GalleryFormat {
    public static final String CONTENT_DATA = "contentdata";
    public static final String CTRL_RESULT = "ctrlResult";
    public static final String DEFAULT_IMAGE = "defaultImage";
    public static final String DELETE_PICTURE = "ctrlDeletePhoto";
    public static final String FILTER_BY = "filterBy";
    public static final String IMAGE_HEIGHT = "imageHeight";
    public static final String IMAGE_PATH = "imageLocalPath";
    public static final String IMAGE_WIDTH = "imageWidth";
    public static final String LOAD_ALL = "loadAll";
    public static final String MAX_ZOOM = "maxZoom";
    public static final String MIN_ZOOM = "minZoom";
    public static final String NO_PHOTO = "noPhoto";
    public static final String SCAN_BARCODE = "ctrlScanBarcode";
    public static final String SELECT_FROM_GALLERY = "ctrlSelectFromGallery";
    public static final String TAKE_PICTURE = "ctrlCapturePhoto";

    public static GallerySpec parse(final Node nodeFormat) {
        final GallerySpec gallerySpec = new GallerySpec();
        if (nodeFormat.hasAttributes()) {
            String value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.IMAGE_WIDTH);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setImageWidth(Integer.parseInt(value));
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.IMAGE_HEIGHT);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setImageHeight(Integer.parseInt(value));
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.DEFAULT_IMAGE);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setDefaultImage(value);
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.MIN_ZOOM);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setMinZoom(Float.parseFloat(value));
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.MAX_ZOOM);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setMaxZoom(Float.parseFloat(value));
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.NO_PHOTO);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setNoPhoto(value);
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.IMAGE_PATH);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setImagePath(value);
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.LOAD_ALL);
            if (!TextUtils.isEmpty(value)) {
                if (value.equalsIgnoreCase("N")) {
                    gallerySpec.setLoadAll(false);
                }
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.TAKE_PICTURE);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setTakePictureID(value);
            }
            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.DELETE_PICTURE);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setDeletePictureID(value);
            }
            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.SELECT_FROM_GALLERY);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setSelectFromGalleryID(value);
            }
            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.SCAN_BARCODE);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setScanBarcode(value);
            }
            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.CONTENT_DATA);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setContentData(value);
            }

            value = XMLPaserUtil.getAttrValue(nodeFormat,
                    GalleryFormat.FILTER_BY);
            if (!TextUtils.isEmpty(value)) {
                gallerySpec.setFilterBy(value);
            }
        }
        return gallerySpec;
    }
}
